﻿<?php
require_once LIBS_PATH . DS . 'configs' . DS . 'configs.php';
class dbHelper
{
    protected $db_name = '';
    protected $db_user = '';
    protected $db_pass = '';
    protected $db_host = '';
    protected $connection;
    
    public function dbHelper(){
        global $db;
        
        $this->db_name = $db['name'];
        $this->db_user = $db['user'];
        $this->db_pass = $db['pass'];
        $this->db_host = $db['host'];
        
        $this->connection = mysql_connect($this->db_host, $this->db_user, $this->db_pass) or die('Khong ket noi den');
        mysql_select_db($this->db_name) or die('Không có co s? d? li?u'. $this->db_name);
    }
    
    function execQuery($query){
        mysql_query("SET NAMES 'utf8'", $this->connection);
        $_select = mysql_query($query, $this->connection);
        return $_select;
    }
    
    function getNumRows($result){
        return mysql_num_rows($result);
    }
    
    function getAffectedRow(){
        return mysql_affected_rows($this->connection);
    }
    
    function fetchArray($result){
            return mysql_fetch_array($result);
    }
    
    function fetchObject($result, $className = ""){
        if($className == "")
            return mysql_fetch_object($result);
        else
            return mysql_fetch_object($result, $className);
    }
    
    function getInsertId(){
        return mysql_insert_id();
    }
    
    function _destruct(){
        mysql_close();
    }
}
?>